package edu.yourl.web;

import org.apache.wicket.PageParameters;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.repeater.data.ListDataProvider;
import org.apache.wicket.model.Model;
import org.apache.wicket.spring.injection.annot.SpringBean;

import edu.yourl.domain.Gossip;
import edu.yourl.domain.Gossiper;
import edu.yourl.presenter.IGossiperPagePresenter;
import edu.yourl.web.components.ActionBar;
import edu.yourl.web.components.GossipListPanel;

abstract public class GossiperPage extends BasePage implements IGossiperPage {

	public static final String GOSSIPER_PARAMETER = "0";

	@SpringBean(name = "gossiperPagePresenter")
	IGossiperPagePresenter presenter;

	private boolean myPage;

	private String followLink;
	
	private String gossiperSEOId;

	@SuppressWarnings("serial")
	public GossiperPage(PageParameters parameters) {
		super(parameters);
		gossiperSEOId = getPageParameters()
			.getString(GOSSIPER_PARAMETER);
		presenter.init(this);
		add(new Label("name", presenter.getName(this)));
		
		WebMarkupContainer actionBar = new ActionBar("actionBar",new Model<GossiperPage>(this)) {
			@Override
			protected void addToFavorites(AjaxRequestTarget target) {
				presenter.addToFavorites(GossiperPage.this);
				target.addComponent(this);
			}
			
			@Override
			protected boolean isLinkEnabled() {
				return presenter.isFavoriteActionVisible(GossiperPage.this);
			}
		};
		actionBar.setOutputMarkupId(true);
		add(actionBar);
		add(new GossipListPanel("gossips", new ListDataProvider<Gossip>(
				presenter.getList(this))));
	}

	abstract public Class<? extends Gossiper> getGossiperType();

	public String getGossiperSEOId() {
		return gossiperSEOId;
	}
	
	public void setMyPage(boolean isMyPage) {
		this.myPage = isMyPage;
	}
	
	public boolean isMyPage() {
		return myPage;
	}
	
	public void setFollowLink(String followLink) {
		this.followLink = followLink;
	}
	
	public String getFollowLink() {
		return this.followLink;
	}

}
